import { Component, OnInit } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { Product, ProductService, ProdComment } from '../shared/product.service';

@Component({
  selector: 'app-product-detail',
  templateUrl: './product-detail.component.html',
  styleUrls: ['./product-detail.component.css']
})
export class ProductDetailComponent implements OnInit {
  prod: Product;
  comments: ProdComment[];
  isCommentHidden: boolean = true;
  commentContent: string;
  constructor(routeInfo: ActivatedRoute, private _productService: ProductService) {
    console.log(routeInfo);
    let id = routeInfo.snapshot.params["id"];
    console.log(id);
    this._productService.getProductById(id).subscribe(product => {
      this.prod = product;
    });
    this._productService.getCommentsByProdId(id).subscribe(comments => {
      this.comments = comments;
    });
  }

  ngOnInit() {

  }
  postComment(e) {
    let comment = new ProdComment(9, this.commentContent, new Date(), "gainorloss", 5);
    this._productService.AddComment(comment);
    this.commentContent = "";
  }
}
